package org.myy.learn.hot.finish.普通数组;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class 除自身以外数组的乘积 {
    public static int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] ans = new int[n];
        int[] L = new int[n], R = new int[n];
        L[0] = 1;
        for (int i = 1; i < n; i++){
            L[i] = nums[i-1]*L[i-1];
        }
        R[n-1] = 1;
        for (int i = n-2; i >= 0; i--){   //ToDo  大于等于0
            R[i] = nums[i+1]*R[i+1];
        }
        for (int i = 0; i < n; i++){
            ans[i] = L[i] * R[i];
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4};
        log.info("nums:{}:", productExceptSelf(nums));
    }
}
